

//设置树的点击事件
function treeClick(node,e) {
	 if(node.isLeaf()){
		e.stopEvent();
		var n = tab.getComponent(node.id);
		if (!n) {
			var n = tab.add({
				id : node.id,
				title : node.text,
				/*autoLoad:{
					url: 'index.php',
					method:"GET",
					params:{
						controller:node.attributes.controller,
						action:node.attributes.action
					},
					scripts:true
				},*/
				closable:true,
				//listeners: {activate: handleActivate}
				html : '<iframe name="'+node.id+'" width=100% height=500px 　 '+
				'src="index.php?controller='+node.attributes.controller+
				'&action='+node.attributes.action+
				'" frameborder=0  ></iframe>'
				});
		}
		tab.setActiveTab(n);
	 }
}

//生成树
 function treeBuilder(title,location_id,treedata_id){
   var root = new Ext.tree.AsyncTreeNode({
		text: title,
		draggable:false,
		id:treedata_id
		
	});

	var tree = new Ext.tree.TreePanel({
		renderTo:location_id,
		//el:id,
		autoScroll:true,
		root:root,
		animate:true,
		enableDD:false,
		border:false,
		rootVisible:true,
		containerScroll: true,
		loader: new Ext.tree.TreeLoader({
			dataUrl:'treedata.php'
		})
		
	});

    tree.setRootNode(root);
	// render the tree
	tree.render();
	root.expand();
	tree.on('click',treeClick);
 }

//生成标签页
var tab = new Ext.TabPanel({
			region:'center',
			deferredRender:false,
			activeTab:0,
			resizeTabs:true, // turn on tab resizing
			minTabWidth: 115,
			tabWidth:135,
			enableTabScroll:true
		});

Ext.onReady(function(){
   //layout
   var viewport = new Ext.Viewport({
		layout:'border',
		items:[
			new Ext.BoxComponent({
				region:'north',
				el: 'north',
				height:80
			}),new Ext.BoxComponent({
				region:'south',
				el: 'south',
				height:25
			}),{
			region:'west',
			id:'west-panel',
			split:true,
			width: 200,
			minSize: 175,
			maxSize: 400,
			margins:'0 0 0 0',
			layout:'accordion',
			title:'系统菜单',
			collapsible :true,
			layoutConfig:{
				animate:true
				},
		    items: [
			    {
					title:'交易管理',
					border:false,
					html:'<div id="trade" style="overflow:auto;width:100%;height:100%"></div>'
					//iconCls:'nav'
			    },{
					title:'商品管理',
					border:false,
					html:'<div id="goods" style="overflow:auto;width:100%;height:100%"></div>'
					//iconCls:'nav'
			    },{
					title:'库存管理',
					border:false,
					html:'<div id="stock" style="overflow:auto;width:100%;height:100%"></div>'
					//iconCls:'nav'
			    },{
					title:'终端管理',
					border:false,
					html:'<div id="terminal" style="overflow:auto;width:100%;height:100%"></div>'
					//iconCls:'nav'
			    },{
					title:'会员管理',
					border:false,
					//iconCls:'settings',
					html:'<div id="member" style="overflow:auto;width:100%;height:100%"></div>'
			    },{
					title:'员工管理',
					border:false,
					html:'<div id="employee" style="overflow:auto;width:100%;height:100%"></div>'
					//iconCls:'nav'
			    },{
					title:'优惠管理',
					border:false,
					html:'<div id="preferential" style="overflow:auto;width:100%;height:100%"></div>'
					//iconCls:'nav'
			    },{
					title:'统计页面',
					border:false,
					//iconCls:'settings',
					html:'<div id="statistics" style="overflow:auto;width:100%;height:100%"></div>'
			    },{
					title:'系统管理',
					border:false,
					html:'<div id="system" style="overflow:auto;width:100%;height:100%"></div>'
					//iconCls:'nav'
			    }]
			},
	        tab//初始标签页
		 ]
	});

	//设置树形面板
	
	treeBuilder("交易管理",'trade','trade_tree');
    treeBuilder("商品管理",'goods','goods_tree');
	treeBuilder("库存管理",'stock','stock_tree');
	treeBuilder("终端管理",'terminal','terminal_tree');
	treeBuilder("会员管理",'member','member_tree');
	treeBuilder("员工管理",'employee','employee_tree');
	treeBuilder("优惠管理",'preferential','preperential_tree');
	treeBuilder("统计页面",'statistics','statistics_tree');
	treeBuilder("系统管理",'system','system_tree');
	
	
	
	
	
	

    //end loding
	
	setTimeout(
				function() {
					Ext.get('loading').remove();
					Ext.get('loading-mask').fadeOut({remove:true});
				}, 250
			  );
	
});